package com.qf.taobei.service.impl;

import com.qf.taobei.entity.po.Product;
import com.qf.taobei.entity.vo.RespBean;
import com.qf.taobei.mapper.ProductMapper;
import com.qf.taobei.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    ProductMapper productMapper;
    @Override
    public RespBean queryAllProduct() {
        List<Product> list = productMapper.queryAllProduct();
        if(list.size()==0){
            return RespBean.respError("查询所有商品失败");
        }
        return RespBean.respSuccess("获取成功",list);

    }

    @Override
    public RespBean addProduct(Product product) {
        int i = productMapper.addProduct(product);
        if(i==0){
            return RespBean.respError("添加商品失败");
        }
        return RespBean.respSuccess("添加商品成功");
    }

    @Override
    public RespBean updateProductById(Product product) {
        int i = productMapper.updateProductById(product);
        if(i==0){
            return RespBean.respError("更新商品失败");
        }
        return RespBean.respSuccess("更新商品成功");
    }

    @Override
    public RespBean delProductById(Long id) {
        int i = productMapper.delProductById(id);
        if(i==0){
            return RespBean.respError("删除商品失败");
        }
        return RespBean.respSuccess("删除商品成功");
    }
}
